unit u_threadastar;

interface

uses classes,
     //u_engine,
     u_astar,
     u_load;

type

 fred_aster = class(TThread)
  private

    finished : boolean;
    depx, depy, arrx, arry, etage, tx, ty : integer;
    map : t_map_obj;
    ka : t_tabk;
    kamikaze : boolean;
  public
    fred : C_Astar;
    procedure execute; override;
    constructor create;
    procedure init(_depx, _depy, _arrx, _arry, _etage, _tx, _ty : integer ; _map : t_map_obj);
    procedure init_k(_depx, _depy, _arrx, _arry, _etage, _tx, _ty : integer ; _map : t_map_obj; _ka : t_tabk);
    function is_finished : boolean;
    procedure finish;
 end;


implementation

constructor fred_aster.create;
  begin
    inherited create(true);
    finished := false;
    kamikaze := false;
    fred := C_Astar.create;
  end;

procedure fred_aster.Execute;
  begin
    finished := false;
    if kamikaze then
      begin
        finished := fred.init_sg_k(depx,depy,arrx,arry,etage,tx,ty,map,ka);
      end
    else
      begin
        fred.init_sg(depx, depy, arrx, arry, etage,tx,ty, map );
        finished := true;
      end;
  end;

procedure fred_aster.init(_depx, _depy, _arrx, _arry, _etage, _tx, _ty : integer ; _map : t_map_obj);
  begin
    depx := _depx;
    depy := _depy;
    arrx := _arrx;
    arry := _arry;
    etage := _etage;
    tx := _tx;
    ty := _ty;
    map := _map;
  end;

procedure fred_aster.init_k(_depx, _depy, _arrx, _arry, _etage, _tx, _ty : integer ; _map : t_map_obj; _ka : t_tabk);
  begin
    depx := _depx;
    depy := _depy;
    arrx := _arrx;
    arry := _arry;
    etage := _etage;
    tx := _tx;
    ty := _ty;
    map := _map;
    ka := _ka;
    kamikaze := true;
  end;

function fred_aster.is_finished : boolean;
  begin
    Result := finished;
  end;

procedure fred_aster.finish;
begin
  finished := false;
end;

end.
